home *** CD-ROM | disk | FTP | other *** search
- #ifndef __STD_COLLATE__
- #define __STD_COLLATE__
- #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
-
- /***************************************************************************
- *
- * collate - Declarations for the Standard Library character
- * collation facet
- *
- *
- ***************************************************************************
- *
- * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
- * ALL RIGHTS RESERVED *
- * The software and information contained herein are proprietary to, and
- * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
- * intends to preserve as trade secrets such software and information.
- * This software is furnished pursuant to a written license agreement and
- * may be used, copied, transmitted, and stored only in accordance with
- * the terms of such license and with the inclusion of the above copyright
- * notice. This software and information or any other copies thereof may
- * not be provided or otherwise made available to any other person.
- *
- * Notwithstanding any other lease or license that may pertain to, or
- * accompany the delivery of, this computer software and information, the
- * rights of the Government regarding its use, reproduction and disclosure
- * are as set forth in Section 52.227-19 of the FARS Computer
- * Software-Restricted Rights clause.
- *
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 252.227-7013.
- * Contractor/Manufacturer is Rogue Wave Software, Inc.,
- * P.O. Box 2328, Corvallis, Oregon 97339.
- *
- * This computer software and information is distributed with "restricted
- * rights." Use, duplication or disclosure is subject to restrictions as
- * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
- * Computer Software-Restricted Rights (April 1985)." If the Clause at
- * 18-52.227-74 "Rights in Data General" is specified in the contract,
- * then the "Alternate III" clause applies.
- *
- **************************************************************************/
-
-
- #ifndef __STD_RWLOCALE__
- #include "rw/rwlocale.h"
- #endif
-
- #ifndef _RWSTD_NO_NAMESPACE
- namespace __rwstd {
- #endif
-
- // ------------------------------------------------------
- // Implementation class template -- collate_table<charT>.
- // ------------------------------------------------------
-
- // Data structure that drives the collate<charT> process. It contains a
- // binary tree of nodes, each of which defines the collation treatment to be
- // applied to a range of characters.
-
- template <class charT>
- class _RWSTDExportTemplate collate_table {
- public:
- struct node {
- node *left; // Node for charT values that are too small (resp.
- node *right; // too large) for this node
- const charT *table; // Translate table or NULL
- charT minC,maxC; // Range of charT-s covered by this node
- charT offset; // Amount to add to charT if table is NULL
- };
-
- long length; // Length of memory block containing all the nodes
- node root; // Root node of table
- };
-
-
- // -----------------------------------------------------
- // Implementation class template -- collate_data<charT>.
- // -----------------------------------------------------
-
- // collate<charT> derives from this (via rwstd::collate_impl) to get its
- // private data members.
-
- template <class charT>
- class _RWSTDExportTemplate collate_data
- {
- public:
- typedef collate_table<charT> table;
- typedef _TYPENAME table::node node;
-
- const table *table_;
-
- collate_data (const table &t): table_(&t) { }
- charT coll_order (charT) const;
- };
-
- template <class charT>
- _RWSTD_TRICKY_INLINE charT _RWSTDExportTemplate collate_data<charT>::
- coll_order (charT c) const
- {
- const node *t=&table_->root;
- while (t)
- if (c < t->minC)
- t=t->left;
- else if (c > t->maxC)
- t=t->right;
- else {
- if (t->table)
- c=t->table[size_t(c-t->minC)];
- else
- c+=t->offset;
- break;
- }
-
- return c;
- }
-
- // -----------------------------------------------------
- // Implementation class template -- collate_impl<charT>.
- // -----------------------------------------------------
-
- // Facet collate<charT> derives from this to get the part of its behavior that
- // is specialized for char and wchar_t.
-
- template <class charT>
- class _RWSTDExportTemplate collate_impl :
- public collate_data<charT>
- {
- static collate_table<charT> _RWSTDExport default_table_;
- public:
- collate_impl (void):
- collate_data<charT>(default_table_) { }
- };
-
- // Specialization for char.
- _RWSTD_TEMPLATE
- class _RWSTDExport collate_impl<char>:
- public collate_data<char>
- {
- static collate_table<char> default_table_;
- public:
- collate_impl (void):
- collate_data<char>(default_table_) { }
- };
-
-
- // Specialization for wchar_t.
- #ifndef _RWSTD_NO_WIDE_CHAR
- _RWSTD_TEMPLATE
- class _RWSTDExport collate_impl<wchar_t>:
- public collate_data<wchar_t>
- {
- static collate_table<wchar_t> default_table_;
- public:
- collate_impl (void):
- collate_data<wchar_t>(default_table_) { }
- };
- #endif
-
-
- #ifndef _RWSTD_NO_NAMESPACE
- } namespace std {
- #endif
-
- // -----------------------------------------------------
- // Standard character collation facet -- collate<charT>.
- // -----------------------------------------------------
-
- template <class charT>
- class collate: public locale::facet,
- public __RWSTD::collate_impl<charT>
- {
- public:
- typedef charT char_type;
- typedef basic_string<charT,char_traits<charT>,allocator<charT> > string_type;
-
- _EXPLICIT collate (size_t refs=0):
- locale::facet(refs,locale::_rw_collate_category)
- { }
-
- int compare (const charT* low1, const charT* high1,
- const charT* low2, const charT* high2) const
- { return do_compare(low1, high1, low2, high2); }
-
- string_type transform (const charT* low, const charT* high) const
- { return do_transform(low, high); }
-
- long hash (const charT* low, const charT* high) const
- { return do_hash(low, high); }
-
- static locale::id id;
-
- // Implementation:
- enum { facet_cat_ = locale::_rw_collate_category, ok_implicit_ = 1 };
-
- protected:
- virtual ~collate();
-
- virtual int do_compare (const charT* low1, const charT* high1,
- const charT* low2, const charT* high2) const;
- virtual string_type do_transform (const charT* low, const charT* high) const;
- virtual long do_hash (const charT* low, const charT* high) const;
-
- private:
- #ifdef _RWSTD_NO_MEMBER_TEMPLATES
- locale::id &get_id (void) const { return id; }
- #endif
- };
-
- // ------------------------------------------------------
- // Standard facet specialization -- collate_byname<char>.
- // ------------------------------------------------------
- template <class charT>
- class _RWSTDExport collate_byname;
-
- _RWSTD_TEMPLATE
- class _RWSTDExport collate_byname<char>: public collate<char> {
- public:
- _EXPLICIT collate_byname (const char*, size_t refs=0);
- protected:
- virtual ~collate_byname ();
-
- // Virtual member functions, override functions in collate<char>.
- virtual int do_compare (const char* low1, const char* high1,
- const char* low2, const char* high2) const;
- virtual string do_transform (const char* low, const char* high) const;
-
- // The remaining virtual function (do_hash) is inherited from collate<char>
- // in this implementation.
-
- private:
- // Implementation.
- string collate_name_;
- };
-
- // ------------------------------------------------
- // Standard derived facet -- collate_byname<charT>.
- // ------------------------------------------------
-
- template <class charT>
- class _RWSTDExport collate_byname: public collate<charT> {
- public:
- typedef basic_string<charT,char_traits<charT>,
- allocator<charT> > string_type;
-
- _EXPLICIT collate_byname (const char*, size_t refs=0);
-
- protected:
- virtual ~collate_byname();
-
- // Virtual member functions overridden from collate<charT>.
- virtual int do_compare (const charT* low1, const charT* high1,
- const charT* low2, const charT* high2) const;
- virtual string_type do_transform (const charT* low, const charT* high) const;
-
- // The remaining virtual function (do_hash) is inherited from collate<charT>
- // in this implementation.
-
- private:
- // Implementation.
- string_type collate_name_;
- };
-
- #ifndef _RWSTD_NO_NAMESPACE
- } namespace __rwstd {
- #endif
-
- #ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC
- template <class charT>
- inline collate<charT>* _RWSTDExport create_named_facet
- (collate<charT>*,const char *name,size_t refs)
- { return new collate_byname<charT>(name,refs); }
- #else
- _RWSTD_TEMPLATE
- inline _STD::collate<char>* _RWSTDExport create_named_facet
- (_STD::collate<char>*,const char *name,size_t refs)
- { return new collate_byname<char>(name,refs); }
- #ifndef _RWSTD_NO_WIDE_CHAR
- _RWSTD_TEMPLATE
- inline _STD::collate<wchar_t>* _RWSTDExport create_named_facet
- (_STD::collate<wchar_t>*,const char *name,size_t refs)
- { return new collate_byname<wchar_t>(name,refs); }
- #endif
- #endif
-
- #ifndef _RWSTD_NO_NAMESPACE
- }
- #endif
-
- #ifdef _RWSTD_COMPILE_INSTANTIATE
- #include <rw/collate.cc>
- #endif
-
- #pragma option pop
- #endif // __STD_COLLATE__
-